#include "QtSingleAnimationEffect.h"

QtSingleAnimationEffect::QtSingleAnimationEffect(): timer(0)
{
}

QtSingleAnimationEffect::~QtSingleAnimationEffect()
{
	if (timer)
	{
		delete timer;
		timer = 0;
	}
}

QtSingleAnimationEffect::QtSingleAnimationEffect(const QtSingleAnimationEffect& rhs): timer(0), duration(rhs.duration)
{
}

void QtSingleAnimationEffect::SetDuration(unsigned int newDuration)
{
	duration = newDuration;
}



QTimeLine* QtSingleAnimationEffect::Timeline() const
{
	return timer;
}

unsigned int QtSingleAnimationEffect::Duration() const
{
	return duration;
}

void QtSingleAnimationEffect::Start()
{
	if (timer == 0)
	{
		timer = new QTimeLine;
		timer->setCurveShape(QTimeLine::LinearCurve);

		QObject::connect(timer, SIGNAL(finished()), this, SLOT(EmitFinished()));
		QObject::connect(timer, SIGNAL(valueChanged(qreal)), this, SLOT(Update(qreal)));
	}

	SetupAnimation();

	timer->setDuration(duration);
	timer->start();

	EmitStarted();
}